#ifndef _T_STATIC_POOL_H_
#define _T_STATIC_POOL_H_

#include "TStaticArray.h"
#include "../system.h"

//----------------------------------------------
template <typename T, size_t CAPACITY, T NULL_VALUE = 0>
class TStaticPool : public TStaticArray<T, CAPACITY>
{
public:
	TStaticPool();

	size_t		size		() const		{ return m_size; }
	int			add			(const T& oVal);
	void		remove		(const T& oVal);
	void		remove		(int iIndex);
	T&			operator[]	(size_t iIndex);
	const T&	operator[]	(size_t iIndex) const;

protected:
	size_t		m_size;
};

//----------------------------------------------
template <typename T, size_t CAPACITY, T NULL_VALUE>
TStaticPool<T, CAPACITY, NULL_VALUE>::TStaticPool() : m_size(0)
{
	for (size_t i=0; i<CAPACITY; i++)
	{
		m_elements[i] = NULL_VALUE;
	}
}

//----------------------------------------------
template <typename T, size_t CAPACITY, T NULL_VALUE>
int TStaticPool<T, CAPACITY, NULL_VALUE>::add (const T& oVal)
{
	for (size_t i=0; i<CAPACITY; i++)
	{
		if (m_elements[i] == NULL_VALUE)
		{
			m_elements[i] = oVal;
			m_size++;
			return i;
		}
	}
	return -1;
}

//----------------------------------------------
template <typename T, size_t CAPACITY, T NULL_VALUE>
void TStaticPool<T, CAPACITY, NULL_VALUE>::remove (const T& oVal)
{
	for (size_t i=0; i<CAPACITY; i++)
	{
		if (m_elements[i] == oVal)
			m_elements[i] = NULL_VALUE;
	}
}

//----------------------------------------------
template <typename T, size_t CAPACITY, T NULL_VALUE>
void TStaticPool<T, CAPACITY, NULL_VALUE>::remove (int iIndex)
{
	m_elements[i] = NULL_VALUE;
}

//----------------------------------------------
template <typename T, size_t CAPACITY, T NULL_VALUE>
T& TStaticPool<T, CAPACITY, NULL_VALUE>::operator[] (size_t iIndex)
{
	assert(iIndex < CAPACITY);
	return m_elements[iIndex];
}

//----------------------------------------------
template <typename T, size_t CAPACITY, T NULL_VALUE>
const T& TStaticPool<T, CAPACITY, NULL_VALUE>::operator[] (size_t iIndex) const
{
	assert(iIndex < CAPACITY);
	return m_elements[iIndex];
}

#endif
